import { qualityTypeMap, partsStatusMap, serviceTypeMap } from '@/config/dict'
import { byKeyGetItem } from '@/utils'
import { CustomStatus } from '@/components'

export const searchFormItem = [
  {
    type: 'select',
    key: 'qualityType',
    label: '质量类型',
    options: qualityTypeMap
  },
  {
    type: 'select',
    key: 'status',
    label: '状态',
    options: partsStatusMap.map(item => ({ key: item.subKey, value: item.value }))
  }
]

export const tableColumn = (handleEdit, handleStart, handleDelete) => {
  return [
    {
      key: 'qualityContent',
      label: '质量内容',
      minWidth: 240
    },
    {
      key: 'qualityType',
      label: '质量类型',
      minWidth: 140,
      render: (h, scope) => byKeyGetItem(qualityTypeMap, scope.row.qualityType).value
    },
    {
      key: 'serviceType',
      label: '所属模块',
      minWidth: 140,
      render: (h, scope) => byKeyGetItem(serviceTypeMap, scope.row.serviceType).value
    },
    {
      key: 'score',
      label: '扣分',
      minWidth: 140
    },
    {
      key: 'timeLimit',
      label: '处理时限（分钟）',
      minWidth: 140
    },
    {
      key: 'remark',
      label: '说明',
      minWidth: 140
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 140,
      render: (h, scope) => <CustomStatus list={partsStatusMap} value={scope.row.status} subKey='subKey'/>
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '修改',
          authKey: 'd_5_2',
          click: handleEdit
        },
        {
          name: (scope) => scope.row.status === 1 ? '停用' : '开启',
          authKey: 'd_5_4',
          click: (e, row) => handleStart(e, row.status === 1 ? 2 : 1)
        },
        {
          name: '删除',
          authKey: 'd_5_3',
          confirm: '确定删除吗?',
          click: handleDelete
        }
      ]
    }
  ]
}

export const modalFormItem = [
  {
    type: 'select',
    key: 'qualityType',
    label: '质量类型',
    required: true,
    slotAttrs: {
      options: qualityTypeMap
    },
    col: 12
  },
  {
    type: 'select',
    key: 'serviceType',
    label: '所属模块',
    required: true,
    slotAttrs: {
      options: serviceTypeMap
    },
    col: 12
  },
  {
    type: 'input',
    key: 'score',
    label: '扣分',
    required: true,
    col: 12
  },
  {
    type: 'input',
    key: 'timeLimit',
    label: '处理时限',
    required: true,
    slotAttrs: {
      placeholder: '分钟'
    },
    col: 12
  },
  {
    type: 'input',
    key: 'qualityContent',
    label: '质量内容',
    required: true,
    slotAttrs: {
      style: { width: '95.8%' }
    },
    col: 24
  },
  {
    type: 'input',
    key: 'remark',
    label: '说明',
    slotAttrs: {
      style: { width: '95.8%' }
    },
    col: 24
  },
  {
    type: 'radio',
    key: 'status',
    label: '状态',
    required: true,
    slotAttrs: {
      options: partsStatusMap,
      optionKey: { key: 'subKey', value: 'value' }
    },
    col: 24
  }
]

export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}

